# -*- coding: utf-8 -*-
from model import BasicSet

import os
import pickle
import datetime
import wsgiref.handlers

from dateutil.relativedelta import relativedelta

from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.ext.webapp import template
from model import *
import blog
from google.appengine.api import memcache

template.register_template_library('templatefilter')
HOST_DORMAIN_ROOT = '/'

class AddArtical(blog.BasePage):
  def get(self):
    self.generate('base.html',{'editormode':True})

  def post(self):
    artical = Articals()
    artical.title = self.request.get('firsttitle')
    artical.secondtitle = self.request.get('secondtitle')
    artical.content = self.request.get('content')
    artical.author = users.get_current_user().nickname()
    artical.init_put()
    self.redirect("/")


class ArticalPage(blog.BasePage):
  def get(self):
      self.generate('base.html')


def main():
  application = webapp.WSGIApplication(
                                       [
                                        ('/archive/([12]\d\d\d)/(\d|[01]\d)/*$',blog.ArchiveView),
                                        ('/([12]\d\d\d)/(\d|[01]\d)/([\w]+)/*$',blog.SingleArtical),
                                        ('/rss.xml',blog.RSSHandler),
                                        ('/editable',blog.Jeditable),
                                        ('/navigate',blog.Navigate),
                                        ('/artical/add',AddArtical),
                                        ('/',ArticalPage)
                                       ],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)


if __name__ == "__main__":
  main()
